package com.yycwxt.modules.admin.operatefee;

import com.yycwxt.domain.OperateFee;
import com.yycwxt.modules.admin.store.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@Api
@RestController
@Validated
@RequestMapping("/OperateFees")
public class OperateFeeController {

    private final OperateFeeService operateFeeService;


    public OperateFeeController(OperateFeeService operateFeeService){this.operateFeeService = operateFeeService;}

    @GetMapping()
    @ApiOperation("查询全部")
    public List<OperateFee> selectAll(){return operateFeeService.list();}

    @GetMapping("/{id}")
    @ApiOperation("查询操作费用")
    public OperateFee getById(@PathVariable Integer id){
        return operateFeeService.getById(id);
    }

    @PostMapping()
    @ApiOperation("添加操作费用")
    public boolean addOperateFee(@ApiParam(name = "OperateFee对象",required = true, type = "operatefee") @RequestBody OperateFee operateFee){
        return operateFeeService.save(operateFee);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除操作费用")
    public boolean deleteOperateFee(@ApiParam(name = "ID值",required = true, type = "int") @PathVariable Integer id){
        return operateFeeService.removeById(id);
    }

    @PutMapping()
    @ApiOperation("修改操作费用")
    public boolean updateOperateFee(@ApiParam(name = "OperateFee对象",required = true, type = "operatefee") @RequestBody OperateFee operateFee){
        return operateFeeService.updateById(operateFee);
    }

    @PostMapping("/upload")
    @ApiOperation("Excel导入数据")
    public Result excelToDatabase(@ApiParam(value = "是否删除全部历史记录", type = "boolean") @RequestParam boolean deleteHistory,
                                  @ApiParam(value = "上传文件", type = "_file") @RequestPart("file") MultipartFile file) {
        Result result = new Result();
        if(operateFeeService.importFileToDB(deleteHistory, file)){
            result.setCode("200");
            result.setMsg("添加成功");
        }else {
            result.setCode("500");
            result.setMsg("添加失败");
        }
        return result;
    }

    @GetMapping("/provider")
    public List<Map<String, Object>> greet(){
        return operateFeeService.selectBcf(202208);
    }
}
